package com.foo.web.controller.api;

import java.sql.SQLException;
import java.util.List;

import com.foo.common.enums.OperatorType;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import com.foo.common.annotation.Log;
import com.foo.common.enums.BusinessType;
import com.foo.wechat.domain.WxUser;
import com.foo.wechat.service.IWxUserService;
import com.foo.common.core.controller.BaseController;
import com.foo.common.core.domain.AjaxResult;

/**
 * 用户关联Api
 *
 * @author foo
 * @date 2025-11-10
 */
@Controller
@RequestMapping("/wechat/api/user")
public class WxUserApi extends BaseController
{
    @Autowired
    private IWxUserService wxUserService;

    /**
     * 查询用户关联列表
     */
    @GetMapping("/list")
    @ResponseBody
    public AjaxResult list(WxUser wxUser,Integer pageNum, Integer pageSize)
    {
        if(pageNum != null){
            Integer size = 10;
            if(pageSize != null){
                size = pageSize;
            }
            PageHelper.startPage(pageNum, size);
        }
        List<WxUser> list = wxUserService.selectWxUserList(wxUser);
        return AjaxResult.success(list);
    }

    /**
     * 查询用户关联详情
     */
    @GetMapping("/detail")
    @ResponseBody
    @Log(title = "用户关联", businessType = BusinessType.Detail, operatorType = OperatorType.MOBILE)
    public AjaxResult detail(Long userId)
    {
        return AjaxResult.success(wxUserService.selectWxUserById(userId));
    }


    /**
     * 修改用户关联
     */
    @PostMapping("/edit")
    @ResponseBody
    @Log(title = "用户关联", businessType = BusinessType.UPDATE, operatorType = OperatorType.MOBILE)
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult editSave(WxUser wxUser)
    {
        return toAjax(wxUserService.updateWxUser(wxUser));
    }



}
